
start:

// ========================================================
// Write a Number to Memory and Read It Back
//
// Memory address: 0x00001000
// Test number:    12345 (0x00003039)
//
// Results:
//     x3 = value read back from memory
//     x4 = 1 if successful
//     x4 = 0 if verification failed
// ========================================================

// Load memory address 0x00001000 into x1
lui   x1, 1                  // x1 = 0x00001000

// Create test number 12345
addi  x2, x2, 12345             // x2 = 0x00003039 = 12345

// Write the number to memory
sw    x2, 0(x1)                // Memory[0x1000] = x2

// Read the number back
lw    x3, 0(x1)                // x3 = Memory[0x1000]

// Display the values
cout << "Original number: " << x2 << endl;
cout << "Number read back: " << x3 << endl;

// Compare the two values
bne   x2, x3, failed           // Branch if values differ

// Verification succeeded
addi  x4, x0, 1                // x4 = 1

cout << "SUCCESS: Memory values match." << endl;

jal   x0, finished             // Skip failure section

failed:
addi  x4, x0, 0                // x4 = 0

cout << "FAILED: Memory values do not match." << endl;

finished:
cout << "Verification result: " << x4 << endl;
